﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SCRUM.Core.BusinessObjects;
using SCRUM.Core.DataProviders;
using System.Collections.Specialized;

namespace SCRUM.Core.DAO
{
    /// <summary>
    /// Data access object for widget settings.
    /// </summary>
    public static class DAOWidgetSettings
    {
        /// <summary>
        /// Saves the settings.
        /// </summary>
        /// <param name="widget">The associated widget.</param>
        /// <param name="ws">The widget settings.</param>
        public static void SaveSettings(Widget widget, StringDictionary ws)
        {
            ProviderFactory.Provider.SaveWidgetSettings(widget, ws);
        }

        /// <summary>
        /// Saves default settings.
        /// </summary>
        /// <param name="widget">The associated widget.</param>
        /// <param name="ws">The widget settings.</param>
        public static void SaveDefaultSettings(Widget widget, StringDictionary ws)
        {
            ProviderFactory.Provider.SaveDefaultWidgetSettings(widget, ws);
        }

        /// <summary>
        /// Loads the settings.
        /// </summary>
        /// <param name="widget">The widget.</param>
        /// <returns>Specified widget settings.</returns>
        public static StringDictionary LoadSettings(Widget widget)
        {
			return ProviderFactory.Provider.LoadWidgetSettings(widget);
        }

        /// <summary>
        /// DeleteWidget the settings.
        /// </summary>
        /// <param name="widget">The widget.</param>
        /// <param name="key">key value to delete.</param>
        public static void DeleteSetting(Widget widget, string key)
        {
            ProviderFactory.Provider.DeleteSetting(widget, key);
        }

        /// <summary>
        /// Update the setting.
        /// </summary>
        /// <param name="widget">The widget.</param>
        /// <param name="key">key value to delete</param>
        /// <param name="value">The value.</param>
        public static void UpdateSetting(Widget widget, string key, string value)
        {
            ProviderFactory.Provider.UpdateWidgetSetting(widget, key, value);
        }

        /// <summary>
        /// Saves the settings.
        /// </summary>
        /// <param name="widget">The associated widget.</param>
        /// <param name="key">Key value to create/update</param>
        /// <param name="value">The widget setting</param>
        public static void SaveCreateSettings(Widget widget, string key, string value)
        {
			StringDictionary setting = ProviderFactory.Provider.LoadWidgetSettings(widget);
            if (setting.ContainsKey(key))
            {
                UpdateSetting(widget, key, value);
            }
            else
            {
                ProviderFactory.Provider.SaveWidgetSetting(widget, key, value);
            }
        }
    }
}
